package com.kele.service.impl;


import com.kele.entity.Customers;
import com.kele.mapper.CustomersMapper;
import com.kele.mapper.UsersMapper;
import com.kele.service.CustomersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomersServiceImpl implements CustomersService {

    @Autowired
    private CustomersMapper customersMapper;

    @Override
    public List<Customers> getAllCustomers() {
        List<Customers> customersList = customersMapper.getAllCustomers();
        return customersList;
    }

    @Override
    public Customers getCustomerById(int id) {
        return customersMapper.getCustomerById(id);
    }

    @Override
    public Customers getCustomersByStatus(String status) {
        return null;
    }

    @Override
    public Customers getCustomersByCust_name(String Cust_name) {
        Customers customers = customersMapper.getCustomersByCust_name(Cust_name);
        return customers;
    }

    @Override
    public String deleteCustomerByName(String cust_name) {

        int i = customersMapper.deleteCustomerByName(cust_name);
        if(i>0){
            return "删除成功";
        }else {
            return "删除失败";
        }
    }

    @Override
    public int deleteCustomerById(int customer_id) {
        return customersMapper.deleteCustomerById(customer_id);
    }

    @Override
    public int updateCustomer(Customers customer) {
        return customersMapper.updateCustomer(customer);
    }

    @Override
    public String insertCustomer(Customers customer) {

        int checkname = customersMapper.checkname(customer.getCust_name());
        if (checkname==0){
            int result = customersMapper.insertCustomer(customer);
            if (result>0){
                return "创建用户成功!";
            }else {
                return "创建用户失败!";
            }
        }else {

            return "创建用户失败！该用户已经存在";
        }
    }

    @Override
    public List<Customers> queryCustomers(String cust_name, Integer user_id, Integer cust_background, Integer listed,
                                          Integer cust_type, Integer status) {
        return customersMapper.queryCustomers(cust_name, user_id, cust_background, listed, cust_type, status);

    }

    @Override
    public String checkname(String cust_name) {
        int result = customersMapper.checkname(cust_name);
        if (result > 0) {
            return "用户名已存在，不能使用！";
        } else {
            return "用户名可以使用！";
        }
    }

    @Override
    public int getCustomerByIdCustName(String cust_name) {
        return customersMapper.getCustomerByIdCustName(cust_name);
    }
}
